# Note: we include the additional tweaking of top_builddir, so that LIBTOOL
# resolves to the correct place.
top_builddir=@top_builddir@/../..
top_srcdir=@top_srcdir@
srcdir=@srcdir@

include $(top_builddir)/Make.rules

.SUFFIXES: .la .lo

SHARED_CFLAGS=-DPR_SHARED_MODULE
SHARED_LDFLAGS=-avoid-version -export-dynamic -module
VPATH=@srcdir@

MODULE_NAME=mod_snmp
MODULE_OBJS=mod_snmp.o asn1.o smi.o pdu.o msg.o db.o mib.o packet.o \
  uptime.o notify.o
SHARED_MODULE_OBJS=mod_snmp.lo asn1.lo smi.lo pdu.lo msg.lo db.lo mib.lo \
  packet.lo uptime.lo notify.lo

# Necessary redefinitions
INCLUDES=-I. -I../.. -I../../include -I$(top_srcdir)/../../include @INCLUDES@
CPPFLAGS=$(ADDL_CPPFLAGS) -DHAVE_CONFIG_H $(DEFAULT_PATHS) $(PLATFORM) $(INCLUDES)
LDFLAGS=-L../../lib @LDFLAGS@

.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<

.c.lo:
	$(LIBTOOL) --mode=compile --tag=CC $(CC) $(CPPFLAGS) $(CFLAGS) $(SHARED_CFLAGS) -c $<

shared: $(SHARED_MODULE_OBJS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) -o $(MODULE_NAME).la $(SHARED_MODULE_OBJS) -rpath $(LIBEXECDIR) $(LDFLAGS) $(SHARED_LDFLAGS) $(SHARED_MODULE_LIBS) `cat $(top_srcdir)/$(MODULE_NAME).c | grep '$$Libraries:' | sed -e 's/^.*\$$Libraries: \(.*\)\\$$/\1/'`

static: $(MODULE_OBJS)
	$(AR) rc $(MODULE_NAME).a $(MODULE_OBJS)
	$(RANLIB) $(MODULE_NAME).a

install: install-headers install-misc
	if [ -f $(MODULE_NAME).la ] ; then \
		$(LIBTOOL) --mode=install --tag=CC $(INSTALL_BIN) $(MODULE_NAME).la $(DESTDIR)$(LIBEXECDIR) ; \
	fi

# BSD install -d doesn't work, so ...
$(DESTDIR)$(includedir) $(DESTDIR)$(includedir)/proftpd:
	@if [ ! -d $@ ]; then \
		mkdir -p $@; \
		chown $(INSTALL_USER):$(INSTALL_GROUP) $@; \
		chmod 0755 $@; \
	fi

install-headers: $(DESTDIR)$(includedir)/proftpd
	$(INSTALL_MAN) $(MODULE_NAME).h $(DESTDIR)$(includedir)/proftpd/$(MODULE_NAME).h

install-misc:
	$(INSTALL) -o $(INSTALL_USER) -g $(INSTALL_GROUP) -m 0644 $(top_srcdir)/PROFTPD-MIB.txt $(DESTDIR)$(sysconfdir)/PROFTPD-MIB.txt

clean:
	$(LIBTOOL) --mode=clean $(RM) $(MODULE_NAME).a $(MODULE_NAME).la *.o *.lo .libs/*.o

dist: clean
	$(RM) Makefile $(MODULE_NAME).h config.status config.cache config.log *.gcda *.gcno
	-$(RM) -r .git/ CVS/ RCS/
